package generic;

public class NumberCollection<T> {

    private T value ;

    public NumberCollection(T value) {
        this.value = value;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public static void main(String[] args) {
        NumberCollection<Integer> integerNumberCollection = new NumberCollection<>(1);
        NumberCollection<Long> longNumberCollection =new NumberCollection<>(999L);
        NumberCollection<Number> numberNumberCollection = new NumberCollection<>(2);

//        printLong(longNumberCollection);
//        printInteger(integerNumberCollection);
//
//        print(longNumberCollection);
//        print(integerNumberCollection);

//        NumberCollection<String> stringNumberCollection =new NumberCollection<>("abc");
//        print(stringNumberCollection);
//        printUp(stringNumberCollection);
//
//        printDown(integerNumberCollection);
//        printDown(numberNumberCollection);
//        printDown(longNumberCollection);

    }

    public static void  printLong(NumberCollection<Long> collection) {
        Long value = collection.getValue();
        System.out.println(value);
    }
    public static void  printInteger(NumberCollection<Integer> collection) {
        Integer value = collection.getValue();
        System.out.println(value);
    }

    //泛型通配符
    public static void  print (NumberCollection<?> collection) {
        Object value = collection.getValue();
        System.out.println(value);
    }

    //上边界通配符
    public static void  printUp (NumberCollection<? extends Number> collection) {
        Object value = collection.getValue();
        System.out.println(value);
    }

    //下边界通配符
    public static void  printDown (NumberCollection<? super Integer> collection) {
        Object value = collection.getValue();
        System.out.println(value);
    }

}
